package com.tengju.activity.domain.model.activity;

import com.tengju.activity.domain.shared.Formatter;
import lombok.Value;

import java.math.BigDecimal;
import java.util.Optional;

@Value
public class SaleSituation {

    private BigDecimal saleTarget;

    private BigDecimal sales;

    private BigDecimal completionRate;

    public String completionRate() {

        if (completionRate != null && completionRate.compareTo(BigDecimal.ONE) >= 0) {
            return "100.00%";
        }

        return Formatter.percent(Optional.ofNullable(completionRate).map(BigDecimal::doubleValue).orElse(0.00), 2);

    }


}
